package xyz.awesomeman.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import xyz.awesomeman.dao.UserDao;
import xyz.awesomeman.entity.User;
import xyz.awesomeman.service.UserService;

@RestController
public class UserController {
	@Autowired
	UserService userService;
	@Autowired
	UserDao userDao;
//	使用jdbctemplate
	@RequestMapping("/addUser")
	public String addUser(@RequestParam String username,@RequestParam String password) {
		userService.addUser(username, password);
		return "success";
	}
	@RequestMapping("/addUser1/{variable1}/{variable2}")
	public String addUser1(@PathVariable String variable1,@PathVariable String variable2) {
		userService.addUser(variable1, variable2);
		return "success";
	}
//	使用jpa
	@RequestMapping("/getInfo/{id}")
	public User getInfo(@PathVariable Integer id) {
		User user = userDao.getOne(id);
		return user;
	}
	@RequestMapping("/test")
	public Map<String,String> test() {
		Map<String,String> map = new HashMap<String, String>();
		map.put("name", "ywj");
		return map;
	}
	
	@RequestMapping("/getUser/{id}")
	public User getUser(@PathVariable Integer id) {
		User user = userService.findById(id);
		return user;
	}
	
}
